<?php
$GLOBALS['Md'] = "TimeClock";
$GLOBALS['Pd'] = "N";
require_once($_SERVER['DOCUMENT_ROOT']."/defaultconf.mex");
print heade(); 
print body(); 
module($BSD['DB00']);
office_header($_SESSION[$SESSOF]);
include($GLOBALS['PAD']."Modules/Exchange/main.obj.php");
include($GLOBALS['PAD']."Modules/Exchange/nav.views.php");
print NavFront();
// ENVIA OPERA��O
if (isset($_POST['OperationChange']) && $_POST['OperationChange'] == "Expeditar" && $_POST['ref_malote'] != "") {
	
	$QMalRef = "INSERT INTO exchange_bags (number,expedict_time) VALUES ('{$_POST['bag_number']}','{$_POST['expedict_time']}'";
	$MalRef = $GLOBALS['CONN']->db_query($QMalRef);

	$Malote = $_POST['malote'];
	$Ref = $_POST['ref'];
	$C = count($Malote);
	for ($c = 1; $c <= $C; $c++) {
	$CSave = "UPDATE exchange_operations SET malote = '{$Malote[$C]}' WHERE ref = '{$Ref[$C]}'";
	$GLOBALS['CONN']->db_query($CSave);
	}
	
	$QBagUpdate = "UPDATE exchange_bags SET operations_total = '{$C}'";
	$BagUpdate = $GLOBALS['CONN']->db_query($QBagUpdate);
	
	
	$Msg->SEND_OPERATION = "Expedi��o Efectuada para as opera��es selecionadas.";
} else {
	$Msg->SEND_OPERATION = "Preencha todos os campos.";
	}
?>
<script charset="utf-8" type="text/javascript" src="../../../Shared/Libraries/Objects/slide.js"></script>
<table width="100%"  border="0" cellpadding="10">
  <tr>
    <td>
  <?php if (!isset($_POST['OperationChange'])) { ?>

	<form action="index.php" method="post">

 <table width="100%"  border="0" cellpadding="6" cellspacing="3">
  <tr bgcolor="#009999">
<td colspan="2">Dados do Malote</td>
</tr>
<tr bgcolor="#F2F2F2">
<td>Valor Total em Caixa: 
<?php 
	$Total = 0;
	$ResidProfit = 0;
	$QBagCalculate = "SELECT * FROM exchange_operations WHERE malote = '0' AND main_office_ref = '{$_SESSION[$SESSOF]}'";
	$BagCalculate = $GLOBALS['CONN']->db_array($QBagCalculate);
	for ($t = 1; $t <= $BagCalculate[0]; $t++) {

	$Total = $Total+$BagCalculate[$t]['payed'];
	$ResidProfit = $ResidProfit+$BagCalculate[$t]['acerto'];
	$TotalResidProfit = $Total-$ResidProfit;
	}
	print number_format($Total,2).currency_output("1","icon"); ?></td>
<td>Data de expedic��o: <?php echo form_input_time("expedict_time",$GLOBALS['T']);?></td>
</tr>
<tr bgcolor="#F2F2F2">
<td>
	Total de Opera��es : 
<?php 
	$Bags['costs'] = "10�";
	$BagCalculate = $GLOBALS['CONN']->db_array($QBagCalculate);
	print count($BagCalculate); ?><br>
	Lucro Residual: <?php echo number_format($TotalResidProfit,2).currency_output("1","icon");?><br>
	Despesas de Envio: <?php echo $Bags['costs'];?><br>
	<b>Total Liquido: <?php 
	print $TotalLiq = number_format($Total-$Bags['costs'],2).currency_output("1","icon"); 
	?></b></td>
<td>N�mero do Malote: <input name="bag_number" type="text" size="4" maxlength="10"></td>
</tr>
	<tr bgcolor="#F2F2F2">
	<td>Deseja expeditar este valor?</td>
	<td><input name="OperationChange" type="submit" value="Expeditar"></td>
	</tr>
</table>
	</form>
	<?php } else { 
	print $Msg->SEND_OPERATION;
	}?>
	
	</td>
  </tr>
</table>
<?php print footer(); ?>